package h_10_27;

/**
 * 2024. 考试的最大困扰度
 * https://leetcode.cn/problems/maximize-the-confusion-of-an-exam/description/
 */
public class Main1 {
    public int maxConsecutiveAnswers(String answerKey, int k) {
        char[] s = answerKey.toCharArray();
        int n = s.length;
        int left = 0;
        int right = 0;
        int ret = 0;
        int[] arr = new int[2]; // 0为t，1为f
        while(right < n) {
            char ch = s[right];
            if(ch == 'T') {
                arr[0]++;
            }else {
                arr[1]++;
            }

            while(arr[0] > k &&arr[1] > k) {
                char out = s[left];
                if (out == 'T') {
                    arr[0]--;
                }else {
                    arr[1]--;
                }
                left++;
            }

            ret = Math.max(ret,right - left + 1);
            right++;
        }
        return ret;
    }
}
